<template>
	<view class="page-container">
		<view class="login-logo"><image :src="'https://static.member.stourweb.cn/uniapp/static/images/' + 'uni-wechat-login-icon.png'" mode="aspectFill"></image></view>
		<view class="login-tit">该操作需要获取您的用户信息</view>
		<button v-if="isShowPrivacy" class="login-bind-btn" @click="layPrivacy">登录</button>
		<button v-else class="login-bind-btn" type="default" @click="login">登录</button>
		<button class="login-cancel-btn" type="default" @click="cancelLog">暂不登录</button>
		<view class="agreement-info">
			<view class="iconfont" @click="changeAgreement" :class="{'on':selected == 1}">{{selected == 0?'&#xe685;':'&#xe6d2;'}}</view>
			<view class="content">同意并遵行<text @click="jumpAgreement('fuwu')" class="info-link">《服务协议》</text>和<text @click="jumpAgreement('xinxi')" class="info-link">《个人信息保护指引》</text></view>
		</view>
		<!-- 预订协议 -->
		
		<st-weixin-privacy :showPrivacy="showPrivacy" @confirm="confirm" @disagree="disagree"></st-weixin-privacy>
		<!-- 用户隐私授权弹窗 -->
				
	</view>
</template>

<script>
	import stWeixinPrivacy from "@/components/st-weixin-privacy.vue";
	import login from '@/utils/login.js'
	export default {
		components: {
			stWeixinPrivacy
		},
		data() {
			return {
				isShowPrivacy: false,
				showPrivacy: false,
				url:'',
				obj:{},
				selected: 0,
			}
		},
		onLoad(options){
			this.url = uni.getStorageSync('toUrl');
			this.getPrivacy();
		},
		onShow() {
			uni.hideHomeButton()
		},
		methods: {
			
			//点击'用户隐私授权弹窗'同意后
			confirm() {
				this.showPrivacy = false;
				this.isShowPrivacy = false;
				let self = this;
				setTimeout(() => {
					self.login();
				}, 500);
			},
			disagree(){
				this.showPrivacy = false;
			},
			getPrivacy() {
				if (uni.getPrivacySetting) {
					uni.getPrivacySetting({
						success: res => {
							if (res.needAuthorization) {
								this.isShowPrivacy = true;
							} else {
								this.isShowPrivacy = false;
							}
						},
						fail: () => {},
						complete: () => {},
					})
				}
			},
			layPrivacy(){
				this.showPrivacy = true;
			},
					
			// 登录
			login(){
				if(this.selected){
					login('', this.url);
				}else{
					uni.showToast({
						title:'请阅读并同意《服务协议》与《个人信息保护指引》',
						icon:'none'
					})
				}	
			},
			
			// 暂不登录
			cancelLog(){
				setTimeout(() => {
					uni.navigateBack()
				}, 200)
			},
			
			// 切换
			changeAgreement() {
				if(this.selected){
					this.selected = 0
				}else{
					this.selected =1
				}
			},
			
			// 跳转预
			jumpAgreement(name){
				if(name == 'fuwu'){
					uni.navigateTo({
						url: '/pages/ubase/agreement?name=' +name +"&adname=" + '服务协议'
					})
				}
				if(name == 'xinxi'){
					uni.navigateTo({
						url: '/pages/ubase/agreement?name=' +name +"&adname=" + '个人信息保护指引'
					})
				}
			}
		}
	}
</script>

<style lang="scss">
	page{
		background-color: $uni-bg-color;
	}
	.page-container{
		padding: 32rpx 74rpx 20rpx;
	}
	.login-logo{
		width: 600rpx;
		height: 493rpx;
		margin: 0 auto;
		image{
			width: 100%;
			height: 100%;
		}
	}
	.login-tit{
		padding-top: 26rpx;
		font-size: 34rpx;
		font-weight: bold;
		text-align: center;
	}
	.login-con{
		padding-top: 28rpx;
		text-align: center;
		font-size: $uni-font-size-sm;
		color: $uni-text-color-grey;
		line-height: 40rpx;
	}
	.login-bind-btn{
		margin-top: 110rpx;
		color: #fff!important;
		font-size: $uni-font-size-base;
		padding: 10rpx 0;
		border-radius: $uni-border-radius-lg;
		background-color: $uni-bg-color-primary !important;
	}
	.login-cancel-btn{
		margin-top: 30rpx;
		color: #333!important;
		font-size: $uni-font-size-base;
		padding: 10rpx 0;
		border-radius: $uni-border-radius-lg;
		background-color: #f2f2f2 !important;
	}
	.agreement-info{
		@extend .displayflex;
		margin-top: 32rpx;
		.iconfont{
			margin: 5rpx 15rpx 0 0;
			color: #a4a3aa;
			&.on{
				color: $uni-color-success;
			}
		}
		.content{
			@extend .flex1;
			width: 500rpx;
			line-height: 1.667;
			font-size: $uni-font-size-sm;
		}
		.info-link{
			color: $uni-color-success;
		}
	}
</style>
